package com.by.feign;

import org.springframework.core.io.InputStreamResource;
import com.by.Service.MinioService;
import com.by.api.feign.MinioFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 江俊俊
 * @version 1.0
 * @description
 * @date 2025/4/16 20:51
 * @since JDK1.8
 */
@RestController
public class MinioFeignController implements MinioFeignClient {

    @Autowired
    MinioService minioService;

    @Override
    public String uploadFile(MultipartFile file) {
        String upload = minioService.upload(file);
        return upload;
    }

    @Override
    public ResponseEntity<InputStreamResource> downloadFile(String filePath)  {
        ResponseEntity<InputStreamResource> download = null;
        try {
            download = minioService.download(filePath);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return download;

    }

    @Override
    public int deleteFile(String filePath) {
        int delete = minioService.delete(filePath);
        return delete;

    }
}
